<template>
	<sw-common-frame :count="dataCount" :loading="loading">
		<template slot="button">
			<el-button size="small" type="primary" icon="el-icon-plus" @click="handleOpenDialog()">新增</el-button>
		</template>
		<template slot="query">
			<el-form size="small" inline>
				<el-form-item>
					<el-input v-model="queryData.name" clearable placeholder="请输入分类名称" style="width: 180px"></el-input>
				</el-form-item>
				<el-form-item>
					<el-select v-model="queryData.extFiled1" clearable placeholder="请选择分类类型" style="width: 140px">
						<el-option v-for="(item, index) in dictData['CLASSIFY_TYPE']" :key="index" :label="item.deName" :value="item.deValue" />
					</el-select>
				</el-form-item>
				<el-form-item>
					<el-select v-model="queryData.status" clearable placeholder="分类状态" style="width: 102px">
						<el-option label="正常" value="1"></el-option>
						<el-option label="禁用" value="2"></el-option>
					</el-select>
				</el-form-item>
				<el-form-item>
					<el-button type="primary" icon="el-icon-search" @click="queryTableData()">查询</el-button>
				</el-form-item>
			</el-form>
		</template>
		<el-table slot="table" :data="tableData" height="100%" stripe>
			<el-table-column label="排序" type="index" width="50" align="center"></el-table-column>
			<el-table-column label="分类名称" prop="name" min-width="200"></el-table-column>
			<el-table-column label="分类类型" min-width="100" :formatter="classifyTypeFormatter" />
			<el-table-column label="分类状态" min-width="100">
				<template slot-scope="{ row }">
					<el-tag size="medium" type="success" v-if="row.status === '1'">正常</el-tag>
					<el-tag size="medium" type="warning" v-if="row.status === '2'">禁用</el-tag>
				</template>
			</el-table-column>
			<el-table-column label="分类描述" prop="des" min-width="320"></el-table-column>
			<el-table-column label="创建时间" prop="createTime" min-width="160"></el-table-column>
			<el-table-column label="操作" width="132">
				<el-button-group slot-scope="{ row }">
					<el-button size="mini" type="warning" @click="handleOpenDialog(row.id)">编辑</el-button>
					<el-button size="mini" type="danger" @click="handleDeleteData(row)">删除</el-button>
				</el-button-group>
			</el-table-column>
		</el-table>
		<template slot="page">
			<sw-pagination :total="dataCount" :page.sync="queryData.page" :limit.sync="queryData.limit" @change="queryTableData()"></sw-pagination>
		</template>
		<form-dialog v-model="formDialog" :data-id="dataId" :list="dictData['CLASSIFY_TYPE']" @refresh="queryTableData()"></form-dialog>
	</sw-common-frame>
</template>

<script>
import formDialog from './form';
import listMixins from '@/mixins/listMixins';
import { queryClassifyList, deleteClassify } from '@/api/exam/testPaperClass';
export default {
	mixins: [listMixins],
	enums: ['CLASSIFY_TYPE'],
	components: { formDialog },
	data() {
		return {
			pageName: '分类',
			classifyType: []
		};
	},
	computed: {
		listFunction() {
			return eval(queryClassifyList);
		},
		deleteFunction() {
			return eval(deleteClassify);
		}
	},
	methods: {
		classifyTypeFormatter(row) {
			let type = 'primary';
			let classify = this.dictData['CLASSIFY_TYPE'];
			let info = classify.find((n) => n.deValue === row.extFiled1);
			if (info?.deValue === '1') {
				type = 'warning';
			} else if (info?.deValue === '2') {
				type = 'danger';
			}
			return this.$createElement('elTag', { attrs: { size: 'small' } }, info?.deName || '未知');
		}
	}
};
</script>

<style lang="scss" scoped></style>
